//
//  CategoryEditViewController.m
//  DemoCoreData
//
//  Created by tangkexiong on 16/3/16.
//  Copyright © 2016年 tangkexiong. All rights reserved.
//

#import "CategoryEditViewController.h"

#import "YCCoreDataManager+CDProductCategory.h"

@implementation CategoryEditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (_category) {
        _nameTxtFld.text = _category.mName;
    }
}

- (IBAction)doneBtnClicked:(id)sender {
    YCProductCategory *category = [[YCProductCategory alloc] init];
    
    category.mName = _nameTxtFld.text;
    
    [[YCCoreDataManager sharedInstance] insertCategory:category block:^(NSError *error, YCProductCategory *category) {
        if (error == nil) {
            if ([self.myDelegate respondsToSelector:@selector(categoryEditVC:didEdit:isAdd:)]) {
                [self.myDelegate categoryEditVC:self didEdit:category isAdd:_category == nil];
            }
        }
    }];
}

@end
